package day22;
import java.util.ArrayList;
import java.util.List;
public class learn {
    public static void main(String[] args) {
        //创建集合
        List<String >list=new ArrayList<String >();
        //添加数据
        list.add("张三丰,北京");
        list.add("李四丰,上海");
        list.add("王小二,北京");
        list.add("小明,河北");
        list.add("王五,北京");
        list.add("小毛,北京");
        //北京
        int sum=0;
        //遍历
        for (int i = 0 ;i<list.size();i++){
            String a = list.get(i);
            try {
                if (a.charAt(4)=='北'&&a.charAt(5)=='京'
                        || a.charAt(3)=='北'&&a.charAt(4)=='京'){
                    sum++;
                    char[] b = a.toCharArray();
                    for (int j =0;j<b.length;j++){
                        if (b[j]!='北'&&b[j]!='京'&&b[j]!=',')
                            System.out.print(b[j]);
                    }
                    System.out.print("  ");
                }
            }catch (Exception e){
            }
        }
        System.out.print("北京有"+  sum+"人"+"\t");

        //上海
        sum=0;
        System.out.println();
        for (int i = 0 ;i<list.size();i++){
            String a = list.get(i);
            try {
                if (a.charAt(4)=='上'&&a.charAt(5)=='海'
                        || a.charAt(3)=='上'&&a.charAt(4)=='海'){
                    sum++;
                    char[] b = a.toCharArray();
                    for (int j =0;j<b.length;j++){
                        if (b[j]!='上'&&b[j]!='海'&&b[j]!=',')
                            System.out.print(b[j]);
                    }
                    System.out.print("  ");
                }
            }catch (Exception e){
            }
        }
        System.out.print("上海有"+  sum+"人"+"\t");

        //河北
        sum=0;
        System.out.println();
        for (int i = 0 ;i<list.size();i++){
            String a = list.get(i);
            try {
                if (a.charAt(4)=='河'&&a.charAt(5)=='北'
                        || a.charAt(3)=='河'&&a.charAt(4)=='北'){
                    sum++;
                    char[] b = a.toCharArray();
                    for (int j =0;j<b.length;j++){
                        if (b[j]!='河'&&b[j]!='北'&&b[j]!=',')
                            System.out.print(b[j]);
                    }
                    System.out.print("  ");
                }
            }catch (Exception e){
            }
        }
        System.out.print("河北有"+sum+"人"+"\t");

    }
}




